<?php
/**
 *    Copyright 2010 Show Framework(www.showframework.cn)
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 * 
 *        http://www.apache.org/licenses/LICENSE-2.0
 * 
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

/**
 * 框架入口文件
 */

define('LIB_ROOT', ROOT . 'lib/');
define('APP_ROOT', ROOT . 'app/');
define('WEB_ROOT', ROOT . 'web/');

/**
 * 注册全局变量
 */
$GLOBALS['show'] = array();

/**
 * 自动加载类函数
 *
 * @param string $name
 * @return void
 * @since v0.6
 */
function __autoload($name)
{
    if (substr($name, 0, 4) === 'Show' && defined('ROOT')) {
        $class = str_replace('_', '/', $name);
        $path = LIB_ROOT . $class . '.php';
        include_once $path;
    } else if (defined('APP_ROOT')) {
        $class = str_replace('_', '/', $name);
        $path = APP_ROOT . $class . '.php';
        include_once $path;
    }
}

/**
 * 这是一个很重要的功能
 * 有待完善
 * The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called. 
 */
function show_error_handler($errno, $errstr, $errfile, $errline, $errcontext)
{
	ob_start();
	var_dump($GLOBALS['show']);
	$dump = ob_get_clean();
	ob_start();
	var_dump($errcontext);
	$context = ob_get_clean();
	ob_end_clean();
	$message = "错误信息: $errstr\n";
	$message .= "文件: $errfile\n";
	$message .= "行数: $errline\n";
	$message .= "Error Code: $errno\n";
	$message .= "Context:\n$context\n\n";
	
	Show_Error::fatal($message);
}

if (IN_DEBUG) {
    ini_set('html_errors', true);
    set_error_handler('show_error_handler', E_ALL | E_STRICT);
} else {
    error_reporting(0);
}

/**
 * 设置一下时区，中国
 */
date_default_timezone_set('PRC');
?>